Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

PlaceDescription.setLongitude   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
var Subject = require('./Subject'),
2
    ResourceReference = require('./ResourceReference'),
3
    TextValue = require('./TextValue'),
4
    GDate = require('./Date'),
5
    utils = require('./utils');
6
7
/**
8
 * A description of a place
9
 * 
10
 * @constructor
11
 * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
12
 */
13
var PlaceDescription = function(json){
14
  
15
  // Protect against forgetting the new keyword when calling the constructor
16
  if(!(this instanceof PlaceDescription)){
17
    return new PlaceDescription(json);
18
  }
19
  
20
  // If the given object is already an instance then just return it. DON'T copy it.
21
  if(PlaceDescription.isInstance(json)){
22
    return json;
23
  }
24
  
25
  Subject.call(this, json);
26
  
27
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
28
    this.setType(json.type);
29
    this.setNames(json.names);
30
    this.setPlace(json.place);
31
    this.setJurisdiction(json.jurisdiction);
32
    this.setTemporalDescription(json.temporalDescription);
33
    this.setSpatialDescription(json.spatialDescription);
34
    this.setLatitude(json.latitude);
35
    this.setLongitude(json.longitude);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
36
  }
37
};
38
39
PlaceDescription.prototype = Object.create(Subject.prototype);
40
41
PlaceDescription._gedxClass = PlaceDescription.prototype._gedxClass = 'GedcomX.PlaceDescription';
42
43
/**
44
 * Check whether the given object is an instance of this class.
45
 * 
46
 * @param {Object} obj
47
 * @returns {Boolean}
48
 */
49
PlaceDescription.isInstance = function(obj){
50
  return utils.isInstance(obj, this._gedxClass);
51
};
52
53
/**
54
 * Get the type
55
 * 
56
 * @returns {String}
57
 */
58
PlaceDescription.prototype.getType = function(){
59
  return this.type;
60
};
61
62
/**
63
 * Set the type
64
 * 
65
 * @param {String} type
66
 * @returns {PlaceDescription}
67
 */
68
PlaceDescription.prototype.setType = function(type){
69
  this.type = type;
70
  return this;
71
};
72
73
/**
74
 * Get the names
75
 * 
76
 * @returns {TextValue[]}
77
 */
78
PlaceDescription.prototype.getNames = function(){
79
  return this.names || [];
80
};
81
82
/**
83
 * Set the names
84
 * 
85
 * @param {TextValue[]|Object[]} names
86
 * @returns {PlaceDescription}
87
 */
88
PlaceDescription.prototype.setNames = function(names){
89
  if(Array.isArray(names)){
90
    var place = this;
91
    place.names = [];
92
    names.forEach(function(n){
93
      place.addName(n);
94
    });
95
  }
96
  return this;
97
};
98
99
/**
100
 * Add the name
101
 * 
102
 * @param {TextValue|Object} name
103
 * @returns {PlaceDescription}
104
 */
105
PlaceDescription.prototype.addName = function(name){
106
  if(name){
107
    if(!Array.isArray(this.names)){
108
      this.names = [];
109
    }
110
    this.names.push(TextValue(name));
111
  }
112
  return this;
113
};
114
115
/**
116
 * Get the place
117
 * 
118
 * @returns {ResourceReference}
119
 */
120
PlaceDescription.prototype.getPlace = function(){
121
  return this.place;
122
};
123
124
/**
125
 * Set the place
126
 * 
127
 * @param {ResourceReference} place
128
 * @returns {PlaceDescription}
129
 */
130
PlaceDescription.prototype.setPlace = function(place){
131
  if(place){
132
    this.place = ResourceReference(place);
133
  }
134
  return this;
135
};
136
137
/**
138
 * Get the jurisdiction
139
 * 
140
 * @returns {ResourceReference}
141
 */
142
PlaceDescription.prototype.getJurisdiction = function(){
143
  return this.jurisdiction;
144
};
145
146
/**
147
 * Set the jurisdiction
148
 * 
149
 * @param {ResourceReference} jurisdiction
150
 * @returns {PlaceDescription}
151
 */
152
PlaceDescription.prototype.setJurisdiction = function(jurisdiction){
153
  if(jurisdiction){
154
    this.jurisdiction = ResourceReference(jurisdiction);
155
  }
156
  return this;
157
};
158
159
/**
160
 * Get the latitude
161
 * 
162
 * @returns {Number}
163
 */
164
PlaceDescription.prototype.getLatitude = function(){
165
  return this.latitude;
166
};
167
168
/**
169
 * Set the latutide
170
 * 
171
 * @param {Number} latitude
172
 * @returns {PlaceDescription}
173
 */
174
PlaceDescription.prototype.setLatitude = function(latitude){
175
  this.latitude = latitude;
176
  return this;
177
};
178
179
/**
180
 * Get the longitude
181
 * 
182
 * @returns {Number}
183
 */
184
PlaceDescription.prototype.getLongitude = function(){
185
  return this.longitude;
186
};
187
188
/**
189
 * Set the latutide
190
 * 
191
 * @param {Number} longitude
192
 * @returns {PlaceDescription}
193
 */
194
PlaceDescription.prototype.setLongitude = function(longitude){
195
  this.longitude = longitude;
196
  return this;
197
};
198
199
/**
200
 * Get the temporal description
201
 * 
202
 * @returns {Date}
203
 */
204
PlaceDescription.prototype.getTemporalDescription = function(){
205
  return this.temporalDescription;
206
};
207
208
/**
209
 * Set the temporal description
210
 * 
211
 * @param {Date} date
212
 * @returns {PlaceDescription}
213
 */
214
PlaceDescription.prototype.setTemporalDescription = function(date){
215
  if(date){
216
    this.temporalDescription = GDate(date);
217
  }
218
  return this;
219
};
220
221
/**
222
 * Get the spatial description
223
 * 
224
 * @returns {ResourceReference}
225
 */
226
PlaceDescription.prototype.getSpatialDescription = function(){
227
  return this.spatialDescription;
228
};
229
230
/**
231
 * Set the spatial description
232
 * 
233
 * @param {ResourceReference} spatial
234
 * @returns {PlaceDescription}
235
 */
236
PlaceDescription.prototype.setSpatialDescription = function(spatial){
237
  if(spatial){
238
    this.spatialDescription = ResourceReference(spatial);
239
  }
240
  return this;
241
};
242
243
/**
244
 * Export the object as JSON
245
 * 
246
 * @return {Object} JSON object
247
 */
248
PlaceDescription.prototype.toJSON = function(){
249
  var json = Subject.prototype.toJSON.call(this);
250
  
251
  if(this.type){
252
    json.type = this.type;
253
  }
254
  
255
  if(this.names){
256
    json.names = this.names.map(function(n){
257
      return n.toJSON();
258
    });
259
  }
260
  
261
  if(this.place){
262
    json.place = this.place.toJSON();
263
  }
264
  
265
  if(this.jurisdiction){
266
    json.jurisdiction = this.jurisdiction.toJSON();
267
  }
268
  
269
  if(this.latitude){
270
    json.latitude = this.latitude;
271
  }
272
  
273
  if(this.longitude){
274
    json.longitude = this.longitude;
275
  }
276
  
277
  if(this.temporalDescription){
278
    json.temporalDescription = this.temporalDescription.toJSON();
279
  }
280
  
281
  if(this.spatialDescription){
282
    json.spatialDescription = this.spatialDescription.toJSON();
283
  }
284
  
285
  return json;
286
};
287
288
module.exports = PlaceDescription;